package model.information;

import java.io.Serializable;
import java.util.Calendar;
import java.util.Observable;
import java.util.ArrayList;

/**
 * A class that represents an event.
 * @author Tobias Møller Kjærsgaard
 * @author Hjalte Blichfeldt Flyger
 * @author Gitte Simonsen
 * @author Claus Lund
 */
public class Event extends Observable implements Serializable {
    private String title;
    private String location;
    private String note;
    private Calendar startTime;
    private Calendar endTime;
    private ArrayList<Contact> participants;

    public Event(String title, String location, String note) {
        this.title = title;
        this.location = location;
        this.note = note;
        this.startTime = Calendar.getInstance();
        this.endTime = Calendar.getInstance();
        this.participants = new ArrayList<Contact>();
    }

    public Event(String title, String location, String note,
            int sYear, int sMonth, int sDate, int sHour, int sMin,
            int eYear, int eMonth, int eDate, int eHour, int eMin) {
        this.title = title;
        this.location = location;
        this.note = note;
        this.startTime = Calendar.getInstance();
        this.endTime = Calendar.getInstance();
        this.startTime.set(sYear, sMonth - 1, sDate, sHour, sMin, 00);
        this.endTime.set(eYear, eMonth - 1, eDate, eHour, eMin, 00);
        this.participants = new ArrayList<Contact>();
    }

    public Calendar getStartTime() {
        return startTime;
    }

    public void setStartTime(int year, int month, int date, int hour, int minute) {
        startTime.set(year, month - 1, date, hour, minute, 0);
        setChanged();
        notifyObservers("event");
    }

    public Calendar getEndTime() {
        return endTime;
    }

    public void setEndTime(int year, int month, int date, int hour, int minute) {
        endTime.set(year, month - 1, date, hour, minute, 0);
        setChanged();
        notifyObservers("event");
    }

    public String getLocation() {
        return location;
    }

    public void setLocation(String location) {
        this.location = location;
        setChanged();
        notifyObservers("event");
    }

    public String getNote() {
        return note;
    }

    public void setNote(String note) {
        this.note = note;
        setChanged();
        notifyObservers("event");
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
        this.setChanged();
        this.notifyObservers("event");
    }

    public ArrayList<Contact> getParticipants() {
        return participants;
    }

    public void addParticipant(Contact c) {
        participants.add(c);
        setChanged();
        notifyObservers("event");
    }

    public void removeParticipant(Contact c) {
        participants.remove(c);
        setChanged();
        notifyObservers("event");
    }

    public String getReadebleStartTime() {
        return startTime.getTime().toString();
    }

    public String getReadableEndTime() {
        return endTime.getTime().toString();
    }

    @Override
    public String toString() {
        return startTime.get(Calendar.DATE) + "-" + (startTime.get(Calendar.MONTH) + 1) + "-" + startTime.get(Calendar.YEAR) + ": " + title;
    }

}
